<?php

class Archive_Controller extends Base_Controller {
	public $restful=true;

	public function get_index($id){
		$archive = Archive::find($id);
		return View::make("home.archive")->with(array(
																											"seoinfo"    => "archive",
																											"links"      => Link::All(),
																											"categories" => categorie::All(),
																											"archive"    => $archive,
																											"comments"    => $archive->comment
																										));
	}

	public function post_index(){
		if (Session::token()==Input::get("csrf_token")){
			$splitword = IoC::resolve('splitword');
			$title     = Input::get("title");
			$words     = explode(" ", $splitword->SplitRMM($title));
			$tags      = null;
			foreach ($words as $v) {
				if (strlen($v)>=6)
				{
					$tags.=$v."|";
				}
			}
			$archive=Auth::user()->archive()->insert(array(
																				"title"        => $title,
																				"body"         => Helper::formatcontent(Input::get("content")),
																				"categorie_id" => Input::get("select_cid")
																			));
			if (is_object($archive)){
				$tag=$archive->tag()->insert(array(
																	"keywords" => $tags
																));
				if (is_object($tag)){
					return Redirect::to("/archive/" . $archive->id);
				}
			}
		}	else{
				echo "系统禁止跨站提交！";
		}	
	}

}